package com.woniu.cinema.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.woniu.common.annotation.Log;
import com.woniu.common.core.controller.BaseController;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.enums.BusinessType;
import com.woniu.cinema.domain.MovieActor;
import com.woniu.cinema.service.MovieActorService;
import com.woniu.common.utils.poi.ExcelUtil;
import com.woniu.common.core.page.TableDataInfo;

/**
 * 电影和演员对应Controller
 * 
 * @author yy
 * @date 2021-04-16
 */
@RestController
@RequestMapping("/cinema/movieactor")
public class MovieActorController extends BaseController
{
    @Autowired
    private MovieActorService movieActorService;

    /**
     * 查询电影和演员对应列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MovieActor movieActor)
    {
        startPage();
        List<MovieActor> list = movieActorService.selectMovieActorList(movieActor);
        return getDataTable(list);
    }

    @RequestMapping("/listAllMovieAcotr")
    public List<MovieActor> listAllMovieActor( )
    {
        List<MovieActor> list = movieActorService.listAllMovieActor();
        return list;
    }

    /**
     * 导出电影和演员对应列表
     */
    @Log(title = "电影和演员对应", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MovieActor movieActor)
    {
        List<MovieActor> list = movieActorService.selectMovieActorList(movieActor);
        ExcelUtil<MovieActor> util = new ExcelUtil<MovieActor>(MovieActor.class);
        return util.exportExcel(list, "movieactor");
    }

    /**
     * 获取电影和演员对应详细信息
     */
    @GetMapping(value = "/{movieActorId}")
    public AjaxResult getInfo(@PathVariable("movieActorId") Long movieActorId)
    {
        return AjaxResult.success(movieActorService.selectMovieActorById(movieActorId));
    }

    /**
     * 新增电影和演员对应
     */
    @Log(title = "电影和演员对应", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MovieActor movieActor)
    {
        return toAjax(movieActorService.insertMovieActor(movieActor));
    }

    /**
     * 修改电影和演员对应
     */
    @Log(title = "电影和演员对应", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MovieActor movieActor)
    {
        return toAjax(movieActorService.updateMovieActor(movieActor));
    }

    /**
     * 删除电影和演员对应
     */
    @Log(title = "电影和演员对应", businessType = BusinessType.DELETE)
	@DeleteMapping("/{movieActorIds}")
    public AjaxResult remove(@PathVariable Long[] movieActorIds)
    {
        return toAjax(movieActorService.deleteMovieActorByIds(movieActorIds));
    }
}
